import {
  request
} from "../../request/index.js";
import {
  login
} from "../../utils/async.js";
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({
  data: {

  },
  onLoad: function (options) {},
  async handleGetUserInfo(e) {
    // console.log(e);
    try {
      // 1.获取用户信息
      const {
        encryptedData,
        rawData,
        iv,
        signature
      } = e.detail
      // 2.获取小程序登录后的值
      const {
        code
      } = await login()
      // 整理参数
      const loginParams = {
        encryptedData,
        rawData,
        iv,
        signature,
        code
      }
      // 3.发送请求，获取token值(接口问题，随便赋值)
      // const {
      //   token
      // } = await request({
      //   url: "/users/wxlogin",
      //   data: loginParams,
      //   methods: 'post'
      // })
      const token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
      // 4.把token存在缓存中，返回上一个页面
      wx.setStorageSync('token', token)
      wx.navigateBack({
        delta: 1,
      })
    } catch (error) {
      console.log(error);
    }
  }
})